﻿

 

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Linq;
using System.Security.Claims;

 
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication;
using Lucene.Net.Analysis;
using System.Collections.Generic;

using Microsoft.EntityFrameworkCore;
using AutoMapper;

using Ccteg.Common;
using Ccteg.DB;

namespace Cctegaq.Api.Controllers
{
    /// <summary>
    /// 企业基本信息
    /// </summary>
    [Route("api/[controller]/[action]")]
    //[ApiExplorerSettings(GroupName = "jcsj")]
    [ApiController]
    public class ENTController : ControllerBase
    {
        private readonly AppAuthenticationSettings _appSettings;
        private readonly MySqlDbContext _dbContext;
        private readonly IMapper _mapper;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="appSettings"></param>
        public ENTController(IOptions<AppAuthenticationSettings> appSettings, MySqlDbContext dbContext, IMapper mapper)
        {
            _appSettings = appSettings.Value;
            _dbContext = dbContext;
            _mapper = mapper;
        }

        /// <summary>
        /// 获取企业信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]

        public ResponseModel<Tree_ViewModel> ENTreeSearch()
        {
            using (_dbContext)
            {
                var response = new ResponseModel<Tree_ViewModel>();
                var query = _dbContext.Ent_Baseinfo.AsNoTracking().Where(x => x.Deleted == false && x.OnState == "启用").OrderBy(x => x.Sort);
                var data = query.Select(_mapper.Map<ent_baseinfo, Tree_ViewModel>);
                response.SetData(TreeHelper.BuildTree(data.ToList()).FirstOrDefault());
                return response;
            }
        }
    }
}
